<template>
  <view>
    <view
      class="registere_serve_box"
      v-for="(item, index) in serviceList"
      :key="item.id"
      @click="toDetails(item.id, index)"
    >
      <view class="registere_serve_image">
        <image :src="item.image != '[]' ? JSON.parse(item.image)[0].url : ''" mode="aspectFill"></image>
      </view>
      <view class="registere_serve_container">
        <view>
          <!-- <image :src="JSON.parse(item.pictures)[0].mainImage"/> -->
        </view>
        <view class="registere_serve_title">{{ item.serverName }}</view>
        <view class="registere_serve_description">{{ item.serverInstruction }}</view>
        <view class="registere_serve_price">
          <view class="service-left">
            <view style="width: 34rpx; height: 32rpx">
              <!-- <u-icon name="home" color="#B3B3B3" size="30"></u-icon> -->
              <!-- <image src="../../static/homeicon/indexicon.png" style="width:100%;height:100%">
									 </image> -->

              <u-image width="100%" height="100%" src="@/static/homeicon/indexicon.png"> </u-image>
            </view>
            <view class="companyInfo" style="color: #b3b3b3; margin-left: 10rpx"
              >
              <!--enterprise_name-->
              {{ item.supplierDate ? item.supplierDate.shopName : '' }}
            </view>
          </view>
          <view class="service-right">
            <text class="current_price">￥{{ Number(item.price).toFixed(2) }}</text>
            <!-- <text class="original_price">￥{{ Number(item.price) * 2 }}</text> -->
          </view>
          <!-- <text class="total_view">
			<u-icon name="eye" color="#B3B3B3" size="30"></u-icon>
            <text>{{item.viewNumber}}</text>
          </text> -->
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    listQuery: {
      type: Object,
      default: () => ({
        currentPage: 1,
        pageSize: 10,
        tree: false,
        userId: '',
      }),
    },
    pageLvel: {
      type: String,
      default: 'two',
    },
    isCollect: {
      type: Boolean,
      default: false,
    },
    category: {
      type: String,
      default: 'two',
    },
    pageSource: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      serviceList: [],
      objectItem: {},
      serviceListArr: [],
      currentPage: 0,
      pageSize: 10,
      total: 0,
      myId: '',
    }
  },
  mounted() {

	
    this.myId = uni.getStorageSync('userId') ? uni.getStorageSync('userId') : ''

   
    // return
    // 处理数据
    if (this.category == 'two') {
     
      this.isCollect ? this.getCollectService() : ''
    } else if (this.category == 'myFoot') {
      
      this.getMyFootService()
    } else {
      this.getLevelService()
    }
  },

  methods: {
    getServiceList() {
      this.$http
        .get('/api/server/list', {
          params: this.listQuery,
        })
        .then((res) => {
           
        if (res.data.data.servers.length > 0) {

            if(this.listQuery.currentPage>1){
                this.serviceList = this.serviceList.concat(res.data.data.servers)
            }else{
              this.serviceList = res.data.data.servers
            }


        } else {
          this.$emit('childFn', 'stopFresh')
        }

        })
    },

    // collected service
    getCollectService() {
      this.$http
        .get('/api/serverLink/list', {
          params: this.listQuery,
        })
        .then((res) => {
          this.serviceList = res.data.data.records
          var total = res.data.data.total
          this.$emit('childFn', total)

        })
    },

    // 浏览足迹
    getMyFootService() {
      if (this.total < (this.listQuery.currentPage - 1) * this.pageSize) return
      console.log("this.total",this.total);
      console.log("this.listQuery.currentPage",this.listQuery.currentPage-1);
      // this.currentPage += 1
      this.$http
        .get('/api/serverLink/list', {
          params: {
            currentPage: this.listQuery.currentPage,
            pageSize: this.pageSize,
            type: 2,
            userId: this.myId,
          },
        })
        .then((res) => {
					this.total = res.data.data.total
          this.serviceList.push(...res.data.data.records)
          if (this.serviceList.length == 0) {
            this.$emit('show', true)
          } else {
            this.$emit('show', false)
          }
        })
    },

    getLevelService() {
      this.$http
        .get('/api/category/server/list/' + this.listQuery.id, {
          params: this.listQuery,
        })
        .then((res) => {
          this.serviceList = res.data.data.server
        })
    },

    toDetails(value, index) {
      this.serviceList[index].viewNumber++
      uni.navigateTo({
        url:
          this.pageLvel == 'two'
            ? '../../pageTwo/productDetails/index?id=' + value
            : '../../../pageTwo/productDetails/index?id=' + value,
      })
    
       //this.countView(value)
    },
    countView(value) {
      this.$http.post('/api/serverInc', {
        userId: this.myId,
        serverId: value,
      }).then((res)=>{
				console.log("res",res.data.data);
			})
    },
  },
}
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
